﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace EMan.GUI.Common.Converters
{
  public class NullToVisibilityConverter : IValueConverter
  {
    public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
    {
      if(value != null) 
        return Visibility.Visible;

      if(parameter != null &&  !(parameter is bool)) throw new ArgumentException("Parameter must be true ('Visibility.Collapsed') or false ('Visibility.Hidden')" );
      var fullyHide = parameter == null || (bool)parameter;
      return fullyHide ? Visibility.Collapsed : Visibility.Hidden;
    }

    public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture )
    {
      throw new NotSupportedException();
    }
  }
}